package com.example.observer;

import com.example.observer.fan.Fan;

import java.util.LinkedList;
import java.util.List;

public class Blogger {
    private final List<Fan> fans = new LinkedList<>();
    private String name;

    public Blogger(String name) {
        this.name = name;
    }

    // 添加粉丝
    public void addFan(Fan fan) {
        fans.add(fan);
    }

    // 删除粉丝
    public void removeFan(Fan fan) {
        fans.remove(fan);
        System.out.println(fan + "粉丝取消关注");
    }

    // 通知所有观察者
    public void notifyFan(String message) {
        for (Fan fan : fans) {
            fan.receiveMessage(message);
        }
        System.out.println("已通知所有观察者");
    }
}
